﻿import QtQuick
import QtQuick.Controls
import FilUI

TextEdit {
    id: control

    property color textColor: {
        if (!enabled) {
            return Qt.rgba(161/255, 161/255, 161/255, 1)
        }
        return Qt.rgba(0, 0, 0, 1)
    }

    color: textColor
    readOnly: true
    activeFocusOnTab: false
    activeFocusOnPress: false
    renderType: FilTheme.nativeText ? Text.NativeRendering : Text.QtRendering
    padding: 0
    leftPadding: 0
    rightPadding: 0
    topPadding: 0
    selectByMouse: true
    selectedTextColor: color
    bottomPadding: 0
    selectionColor: FilTools.withOpacity(FilTheme.primaryColor, 0.5)
    font: FilTextStyle.Body
    onSelectedTextChanged: {
        control.forceActiveFocus()
    }
    MouseArea {
        anchors.fill: parent
        cursorShape: Qt.IBeamCursor
        acceptedButtons: Qt.RightButton
        onClicked: control.echoMode !== TextInput.Password && menu_loader.popup()
    }
    Loader {
        id: menu_loader
        function popup() {
            sourceComponent = menu
        }
        Component.onDestruction: sourceComponent = undefined
    }
    Component {
        id: menu
        FilTextBoxMenu {
            inputItem: control
            Component.onCompleted: {
                popup()
            }
            onClosed: {
                menu_loader.sourceComponent = undefined
            }
        }
    }
}
